/**
 * Created by scutterry on 16/5/18.
 */
class DM {

    public constructor(){
        this.sessId = window.localStorage.getItem("sessid");
        if(window.location.href.indexOf("andytest") > -1){
            Config.httpUrl = "http://andytest.nvzhanshen.com:10009/";
        }
    }
    private static instance:DM;


    private sessId:any;
    public static getInstance():DM{
        if(!DM.instance){
            DM.instance = new DM();
        }
        return DM.instance;
    }



    /**
     * 是否登录
     * @param func 回调函数 
     * @param ths 回调函数 this 引用
     */
    public isLogin(func:any, ths:any):void{
        var url:string;
        if(Config.isDebug){
            url = "./fake/ajax_is_login.json";
            MyNet.get(url, func, ths);
        }else{
            if(this.sessId && this.sessId != ""){
                url = Config.httpUrl + "ajax_is_login/";
                MyNet.post(url, {sessid: this.sessId}, func, ths);
            }else{
                func.call(ths, {code: -1});
            }
        }
    }

    
    
    
    /**
     * 签到信息
     * @param func 回调函数 
     * @param ths 回调函数 this 引用
     */
    public signInfo(func:any, ths:any):void{
        var url:string;
        if(Config.isDebug){
            url = "./fake/sign_info.json";
            MyNet.get(url, func, ths);
        }else{
            url = Config.httpUrl + "ajax_sign_info/";
            var obj:any = {};
            obj.sessid = this.sessId;
            obj.source = 1;
            MyNet.post(url, obj, func, ths);
        }
    }


    public sign(func:any, ths:any):void{
        var url:string;
        if(Config.isDebug){
            url = "./fake/sign.json";
            MyNet.get(url, func, ths);
        }else{
            url = Config.httpUrl + "ajax_sign/";
            var obj:any = {};
            obj.sessid = this.sessId;
            obj.source = 1;
            MyNet.post(url, obj, func, ths);
        }
    }

    public signBefore(day:number, func:any, ths:any):void{
        var url:string;
        if(Config.isDebug){
            url = "./fake/sign.json";
            MyNet.get(url, func, ths);
        }else{
            url = Config.httpUrl + "ajax_sign_before/";
            var obj:any = {day: day};
            obj.sessid = this.sessId;
            obj.source = 1;
            MyNet.post(url, obj, func, ths);
        }
    }


    public gameList(func:any, ths:any):void{
        var url:string = "resource/json/game.json";
        MyNet.get(url, func, ths);
    }

    public movementList(func:any, ths:any):void{
        var url:string = "resource/json/movement.json";
        MyNet.get(url, func, ths);
    }
}

const enum LoginStatus{
    /** 登录成功 */
    success = 0,
    /** 账号错误 */
    user_err = 1,
    /** 密码错误 */
    pwd_err = 2
}